<template>
  <el-table :data="list" style="width: 100%;padding-top: 15px;">
    <el-table-column label="请求提交时间" align="center">
      <template slot-scope="{row}">
        <el-tag :type="row.submitDate | timeFilter">
          {{ row.submitDate }}
        </el-tag>
      </template>
    </el-table-column>
    <el-table-column label="请求用户id" width="100" align="center">
      <template slot-scope="scope">
        {{ scope.row.userId }}
      </template>
    </el-table-column>

  </el-table>
</template>

<script>

import { fetchApply } from '@/api/apply'
export default {
  filters: {
    timeFilter(time) {
      const d = new Date(time).getTime()
      const now = Date.now()
      const diff = (now - d) / 1000
      let status
      if (diff < 3600) {
        status = 0
      } else if (diff < 3600 * 24) {
        status = 1
      } else {
        status = 2
      }
      const statusMap = [
        'success', 'warning', 'danger'
      ]
      return statusMap[status]
    },
    orderNoFilter(str) {
      return str.substring(0, 30)
    }
  },
  data() {
    return {
      list: null
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      fetchApply().then(res => {
        this.list = res.items.slice(0, 10)
      })
    }
  }
}
</script>
